<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>视频资源管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('<spring:message code="common.subbmiting"/>');
                    timeVali($("#btnSubmit"));
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
                $(obj).parent().parent().css("display","none");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/video/eleSourceVideoGroup/">
			<spring:message code="video.list"/>
		</a></li>
		<li class="active"><a href="${ctx}/source/video/eleSourceVideoGroup/form?id=${eleSourceVideoGroup.id}">
			<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit">
				<c:if test="${not empty eleSourceVideoGroup.id}">
					<spring:message code="video.modify"/>
				</c:if>
				<c:if test="${empty eleSourceVideoGroup.id}">
					<spring:message code="video.add"/>
				</c:if>
			</shiro:hasPermission>
			<shiro:lacksPermission name="source:video:eleSourceVideoGroup:edit">
				<spring:message code="video.info"/>
			</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceVideoGroup" action="${ctx}/source/video/eleSourceVideoGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%--<div class="control-group">
			<label class="control-label">auto_play：</label>
			<div class="controls">
				<form:input path="autoPlay" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>--%>
		<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="2" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
			<div class="control-group">
				<label class="control-label"><spring:message code='video'/>：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th><spring:message code="common.dname"/></th>
								<th><spring:message code='Start.play.date'/></th>
								<th><spring:message code='End.play.date'/></th>
								<th>开始播放时间</th>
								<th>结束播放时间</th>
								<th><spring:message code='Continuous.playback.times'/></th>
								<th><spring:message code='Play.sequence.number'/></th>
								<th><spring:message code='video'/></th>
								<th><spring:message code='Live.link'/></th>
								<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="eleSourceVideoList">
						</tbody>
						<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><tfoot>
							<tr><td colspan="9"><a href="javascript:" onclick="addRow('#eleSourceVideoList', eleSourceVideoRowIdx, eleSourceVideoTpl);eleSourceVideoRowIdx = eleSourceVideoRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eleSourceVideoTpl">//<!--
						<tr id="eleSourceVideoList{{idx}}">
							<td class="hide">
								<input id="eleSourceVideoList{{idx}}_id" name="eleSourceVideoList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceVideoList{{idx}}_delFlag" name="eleSourceVideoList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_name" name="eleSourceVideoList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="255" class="input-small "/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_startDate" name="eleSourceVideoList[{{idx}}].startDate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.startDate}}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_endDate" name="eleSourceVideoList[{{idx}}].endDate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.endDate}}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_startTime" name="eleSourceVideoList[{{idx}}].startTime" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.startTime}}" onclick="WdatePicker({dateFmt:'HH:mm:ss',isShowClear:false});"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_endTime" name="eleSourceVideoList[{{idx}}].endTime" type="text" readonly="readonly" maxlength="20" class="input-small Wdate "
									value="{{row.endTime}}" onclick="WdatePicker({dateFmt:'HH:mm:ss',isShowClear:false});"/>
							</td>
						
							<td>
								<input id="eleSourceVideoList{{idx}}_frequency" name="eleSourceVideoList[{{idx}}].frequency" type="text" value="{{row.frequency}}" maxlength="10" class="input-mini  digits"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_index" name="eleSourceVideoList[{{idx}}].index" type="text" value="{{row.index}}" maxlength="10" class="input-mini digits"/>
							</td>
							<td>
								<input id="eleSourceVideoList{{idx}}_path" name="eleSourceVideoList[{{idx}}].path" type="hidden" value="{{row.path}}" maxlength="255"/>
								<sys:ckfinder input="eleSourceVideoList{{idx}}_path" type="videos" uploadPath="/source/video/eleSourceVideoGroup" selectMultiple="false"/>
							</td>
							<td>
								<textarea id="eleSourceVideoList{{idx}}_liveUrl" name="eleSourceVideoList[{{idx}}].liveUrl" rows="2" maxlength="255" class="input-small ">{{row.liveUrl}}</textarea>
							</td>
							<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceVideoList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceVideoRowIdx = 0, eleSourceVideoTpl = $("#eleSourceVideoTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceVideoGroup.eleSourceVideoList)};
							for (var i=0; i<data.length; i++){
								addRow('#eleSourceVideoList', eleSourceVideoRowIdx, eleSourceVideoTpl, data[i]);
								eleSourceVideoRowIdx = eleSourceVideoRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
		<div class="form-actions">
			<shiro:hasPermission name="source:video:eleSourceVideoGroup:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.save'/>"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="<spring:message code='common.back'/>" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>